package edu.zju;
import net.tinyos.message.MoteIF;
import net.tinyos.packet.BuildSource;
import net.tinyos.packet.PhoenixSource;
import net.tinyos.util.PrintStreamMessenger;

public class ListenThread implements Runnable{
	private String args1;
	private String args2;
	public ListenThread(String args1,String args2){
		this.args1 = args1;
		this.args2 = args2;
	}
	
	public String mainfunction() {
		return mainfunction(this.args1,this.args2);
	}
	
	public String mainfunction(String args1,String args2) {
		String str = args1 + args2;
		int USBnum = 0;

		String source = null;
		if (!args1.equals("-comm")) {
			System.exit(1);
		}
		source = args2;
		if (source.charAt(19) != ':') {
			USBnum += source.charAt(19) - '0';
			USBnum += (source.charAt(18) - '0') * 10;
		} else {
			USBnum = source.charAt(18) - '0';
		}

		PhoenixSource phoenix = null;
		if (source == null) {
			phoenix = BuildSource.makePhoenix(PrintStreamMessenger.err);
		} else {
			phoenix = BuildSource.makePhoenix(source, PrintStreamMessenger.err);
		}
		MoteIF mif = new MoteIF(phoenix);
		DBPrintfClient client = new DBPrintfClient(mif, USBnum);
		return str + "*" + USBnum;
	}

	@Override
	public void run() {
		mainfunction();
	}
}

